package com.collection.linkedlist;

import java.util.Iterator;
import java.util.LinkedList;

public class IterateThroughLinkedListUsingIteratorExample {
	 public static void main(String[] args) {
		 
		    //create LinkedList object
		    LinkedList lList = new LinkedList();
		   
		    //add elements to LinkedList
		    lList.add("1");
		    lList.add("2");
		    lList.add("3");
		    lList.add("4");
		    lList.add("5");
		 
		    /*
		     * To get an Iterator object of LinkedList, use
		     * Iterator iterator() method.
		     */
		   
		    Iterator itr = lList.iterator();
		   
		    System.out.println("Iterating through elements of Java LinkedList...");
		    System.out.println("LinkedList contains : ");
		    while(itr.hasNext())
		    {
		      System.out.println(itr.next());
		    }
		 
		  }
}
